package cn.seocoo.platform.web.controller.rolation;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.seocoo.platform.common.annotation.Log;
import cn.seocoo.platform.common.enums.BusinessType;
import cn.seocoo.platform.rotation.domain.RotationChart;
import cn.seocoo.platform.rotation.service.IRotationChartService;
import cn.seocoo.platform.common.core.controller.BaseController;
import cn.seocoo.platform.common.core.page.TableDataInfo;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.poi.ExcelUtil;

/**
 * 轮播图 信息操作处理
 * 
 * @author wujian
 * @date 2020-01-06
 */
@Controller
@RequestMapping("/rotation/rotationChart")
public class RotationChartController extends BaseController
{
    private String prefix = "rotation/rotationChart";
	
	@Autowired
	private IRotationChartService rotationChartService;
	
	@RequiresPermissions("rotation:rotationChart:view")
	@GetMapping()
	public String rotationChart()
	{
	    return prefix + "/rotationChart";
	}
	
	/**
	 * 查询轮播图列表
	 */
	@RequiresPermissions("rotation:rotationChart:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(RotationChart rotationChart)
	{
		startPage();
        List<RotationChart> list = rotationChartService.selectRotationChartList(rotationChart);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出轮播图列表
	 */
	@RequiresPermissions("rotation:rotationChart:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RotationChart rotationChart)
    {
    	List<RotationChart> list = rotationChartService.selectRotationChartList(rotationChart);
        ExcelUtil<RotationChart> util = new ExcelUtil<RotationChart>(RotationChart.class);
        return util.exportExcel(list, "rotationChart");
    }
	
	/**
	 * 新增轮播图
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存轮播图
	 */
	@RequiresPermissions("rotation:rotationChart:add")
	@Log(title = "轮播图", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(RotationChart rotationChart)
	{		
		return toAjax(rotationChartService.insertRotationChart(rotationChart));
	}

	/**
	 * 修改轮播图
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		RotationChart rotationChart = rotationChartService.selectRotationChartById(id);
		mmap.put("rotationChart", rotationChart);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存轮播图
	 */
	@RequiresPermissions("rotation:rotationChart:edit")
	@Log(title = "轮播图", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(RotationChart rotationChart)
	{		
		return toAjax(rotationChartService.updateRotationChart(rotationChart));
	}
	
	/**
	 * 删除轮播图
	 */
	@RequiresPermissions("rotation:rotationChart:remove")
	@Log(title = "轮播图", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(rotationChartService.deleteRotationChartByIds(ids));
	}
	
}
